package com.edu.chapter06;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    GameAdapter gameAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        RecyclerView recyclerView = findViewById(R.id.rv_game);

        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("QQ");
        arrayList.add("微信");
        arrayList.add("飞书");
        arrayList.add("小红书");
        arrayList.add("美团");
        arrayList.add("火影忍者");
        arrayList.add("海贼王");
        arrayList.add("BiliBili");
        arrayList.add("浏览器");
        arrayList.add("电话");
        arrayList.add("邮件");

//        GameAdapter gameAdapter = new GameAdapter(arrayList);
        // 创建适配器并设置删除回调
        gameAdapter = new GameAdapter(arrayList, position -> {
            // 从数据源删除指定项
            arrayList.remove(position);
            // 通知适配器更新
            gameAdapter.notifyItemRemoved(position);
        });
        recyclerView.setAdapter(gameAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }
}